package learning.socket3;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	public static void main(String[] args) {
		ServerSocket ss=null;
		File srf=new File("D:/download/win7_professional.iso");
		try {
			ss=new ServerSocket(2222);
			while(true){
				System.out.println("waiting...");
				Socket s=ss.accept();
				System.out.println("wellcome "+s.getInetAddress().getHostName());
				BufferedInputStream bis=new BufferedInputStream(new FileInputStream(srf));
				BufferedOutputStream bos=new BufferedOutputStream(s.getOutputStream());
				byte[] bb=new byte[1024*1024];
				int len=0;
				while((len=bis.read(bb))!=-1){
					bos.write(bb, 0, len);
					bos.flush();
				}
				bis.close();
				bos.close();
				s.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
